package com.code.day20;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class DemoFileOutputStream01 {


    public static void main(String[] args) throws IOException {

        //method1();
        //method2();
        //method3();
        method4();

    }

    private static void method1() throws IOException {
        // 没有文件可以创建
        FileOutputStream fos = new FileOutputStream("D:\\1.txt");
        fos.write("你好".getBytes());
        fos.close();
    }

    /*
     * write(byte[] b, int off, int len) >一次写一个字节数组的一部分
     */

    private static void method2() throws IOException {
        FileOutputStream fos = new FileOutputStream("D:\\1.txt");
        byte[] bytes = {97,98,99,100,101,102};
        //从第几个索引开始,到第几个
        fos.write(bytes,0,3);
        fos.close();
    }


    /*
     * write(byte[] b) >一次写一个字节数组
     */
    private static void method3() throws IOException {
        FileOutputStream fos = new FileOutputStream("D:\\1.txt");
        byte[] bytes = {97,98,99,100,101,102};
        //从第几个索引开始,到第几个
        fos.write(bytes);
        fos.close();
    }


    /*
     * write(int i) >一次写一个字节
     */
    private static void method4() throws IOException {
        FileOutputStream fos = new FileOutputStream("D:\\1.txt");
        //从第几个索引开始,到第几个
        fos.write(102);
        fos.close();
    }
}
